package com.busi.controller.ruledata;

import com.busi.entity.RuleData;
import com.busi.util.HttpUtils;
import com.busi.util.PropertyUtil;
import com.zcurd.controller.BaseController;

/**   
 * @Title: ruledata
 * @Description: ruledata
 * @author xusai
 * @date 2017-10-09 16:51:56
 * @version V1.0   
 *
 */

public class RuleDataController extends BaseController {
		//列表
		public void list() {
			render("list.html");
		}
		//回显列表
		public void listData(){
			RuleData ruleData=getBean(RuleData.class,"");
			String body = gson.toJson(ruleData);
			String domain = PropertyUtil.getStrValue("new_zx.domain", "");
			String url = domain + "/api/ruleData/findList";
			String[][] headers = {{"Content-Type", "application/json"}};
			String jsonString = HttpUtils.doPost(url, body, headers , 3, 5, "utf-8");
			renderJson(jsonString==null?"":jsonString);		
		}
		
		//增加规则
		public void add() {
			render("add.html");
		}
		
		public void addPage() {
			RuleData ruleData=getBean(RuleData.class,"");
			String body = gson.toJson(ruleData);
			//System.out.println(body+"======================");
			String domain = PropertyUtil.getStrValue("new_zx.domain", "");
			String url = domain + "/api/ruleData/addPage";
			//System.out.println(url+"===================");
			String[][] headers = {{"Content-Type", "application/json"}};
			String jsonString = HttpUtils.doPost(url, body, headers , 3, 5, "utf-8");
			System.out.println(jsonString+"==========================");
			renderSuccess();
			
		}
		
		/*	//添加规则类型
		public void adda() {
			render("detail.html");
		}
		public void add2() {
			RuleData ruleData=getBean(RuleData.class,"");
			String body = gson.toJson(ruleData);
			String domain = PropertyUtil.getStrValue("new_zx.domain", "");
			
			String url = domain + "/api/ruleData/addaPage";
			
			String[][] headers = {{"Content-Type", "application/json"}};
			String jsonString = HttpUtils.doPost(url, body, headers , 3, 5, "utf-8");
			System.out.println(jsonString+"==========================");
			renderJson(jsonString==null?"":jsonString);		
		}*/
		
		/*public void addaPage() {
			RuleData ruleData=getBean(RuleData.class);
			String body = gson.toJson(ruleData);
			String domain = PropertyUtil.getStrValue("new_zx.domain", "");
			
			String url = domain + "/api/ruleData/addaPage";
			
			String[][] headers = {{"Content-Type", "application/json"}};
			String jsonString = HttpUtils.doPost(url, body, headers , 3, 5, "utf-8");
			System.out.println(jsonString+"==========================");
			renderJson(jsonString==null?"":jsonString);		
		}*/
		
		//先查后改
		public void update() {
			RuleData ruleData=getBean(RuleData.class,"");
			String body = gson.toJson(ruleData);
			String domain = PropertyUtil.getStrValue("new_zx.domain", "");
			String url = domain + "/api/ruleData/findOne";
			String[][] headers = {{"Content-Type", "application/json"}};
			String jsonString = HttpUtils.doPost(url, body, headers , 3, 5, "utf-8");
			//System.out.println("???????"+jsonString+"==========================");
			RuleData ruleData2=gson.fromJson(jsonString, RuleData.class);
			setAttr("rule", ruleData2);
			render("update.html");
		}
		//修改页面
		public void updatePage() {
			RuleData ruleData = getBean(RuleData.class,"");
			String body = gson.toJson(ruleData);
			String domain = PropertyUtil.getStrValue("new_zx.domain", "");
			String[][] headers = {{"Content-Type", "application/json"}};
			String url = domain + "/api/ruleData/updatePage";
			String jsonString = HttpUtils.doPost(url, body, headers, 3, 5, "utf-8");
			System.out.println(jsonString+"==========================");
			renderSuccess();
		}
	
		//删除规则
		public void delete(){
			RuleData ruleData = getBean(RuleData.class,"");
			String body = gson.toJson(ruleData);
			String domain = PropertyUtil.getStrValue("new_zx.domain", "");
			String url = domain + "/api/ruleData/deletePage";
			String[][] headers = {{"Content-Type", "application/json"}};
			String jsonString = HttpUtils.doPost(url, body, headers, 3, 5, "utf-8");
			System.out.println(jsonString+"！！！！！=============");
			//JSONObject ret =(JSONObject) JSONObject.parse(jsonString);
			/*RuleData ruleData1 = gson.fromJson(jsonString, RuleData.class);
			setAttr("ruleData", ruleData1);*/
			renderSuccess();
			/*if("0000".equals(ret.get("ret"))){
				renderSuccess();
			}else{
				renderFailed(jsonString=="操作失败！"?"":jsonString);
			}*/
		}
}
